<div class="project-view-title">
<h1>Projects Database</h1>
<div>
	<form method="get" action="">
		<input type="text" name="search">
		<input class="btn btn-primary" type="submit" value="Search">
	</form>
</div>
<% if @projects %>
	<% if @projects.empty? %> 
		<p class='alert error'>Your search did not return any results, please try again</p>
	<% else %>
	<table class="table table-striped">
	  <thead>
	    <tr>
	      <th>Name</th>
	      <th>Members</th>
	      <th>Manager</th>
	      <th>Created</th>
	      <th>Actions</th>
	    </tr>
	  </thead>
	  <tbody>
	
		<% @projects.each do |project| %>
	       
		      <tr>
		        <td><%= project.name %></td>
		        <td><%= project.users.count %></td>
		        <td><%= project.owner.full_name %></td>
		        <td><%= project.created_at.to_s(:slash_time) %></td>
		
		        <td>
		          <% if project.contributor? current_user %>
		          	<%= link_to 'Quit', project_contribution_path(project, current_user), :method => :delete, :confirm => 'Are you sure?', :class => 'btn btn-mini btn-danger' %>
		          <% elsif project.pending_contributor? current_user %>
		          	<%= link_to 'Cancel', "#", :class => 'btn btn-mini btn-primary' %>
                  <% elsif current_user != project.owner%>

		            <%= link_to 'Join', (join_project_path :user_id => current_user.id, :project_id => project.id), :class => 'btn btn-mini btn-success' %>
		          <% end %>
		
		          <% if can? :destroy, project %>
		            <%= link_to 'Delete', project_path(project), :method => :delete, :confirm => 'Are you sure?', :class => 'btn btn-mini btn-danger' %>
		          <% end %>
		        </td>
		      </tr>
		   <%end%>
		
	</tbody>
</table>
<%end%>
<% end %>
   </div>





<!--create_table "projects", :force => true do |t|
    t.datetime "started_at"
    t.datetime "ending_at"
    t.string   "name"
    t.text     "description"
    t.integer  "owner_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end-->
